<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SmartMad Monitor</title>
<link rel="stylesheet" href="../assets/css/bootstrap-spacelab.css" />
<link rel="stylesheet" href="../assets/css/base.css?t=20130516173114" />

  <!-- template
    ================================================== -->
    <script id="t_a" type="text/html">
        <table class="table table-striped table-bordered table-condensed">
            <thead>
                <tr>
                    <th>主机组</th>
                    <th>在线数</th>
                    <th>宕机数</th>
                    <th>正常事件数</th>
                    <th>注意事件数</th>
                    <th>严重事件数</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <% 
					for (var i in list) { var item = list[i];
				 %>
                <tr>
					<td>
						<%= i %>
					</td>                	
                    <td>
                       <div class="<%= item[0] > 0 ? 'success' : '' %>"><%= item[0] ? item[0] : '' %></div>
                    </td>
                    <td>
                       <div class="<%= item[1] > 0 ? 'danger' : '' %>"><%= item[1] ? item[1] : '' %></div>
                    </td>
                    <td>
                    	<div class="<%= item[2] > 0 ? 'success' : '' %>"><%= item[2] ? item[2] : '' %></div>
                    </td>
                    <td>
                        <div class="<%= item[3] > 0 ? 'warning' : '' %>"><%= item[3] ? item[3] : '' %></div>
                    </td>
                    <td>
                        <div class="<%= item[4] > 0 ? 'danger' : '' %>"><%= item[4] ? item[4] : '' %></div>
                    </td>
                    <td>
                    	<% if(item[5] != 0) { %>
						<button class="btn" title="修改" name="modify" data-name="<%= i %>"><i class="icon-edit"></i></button>
						&nbsp;&nbsp;&nbsp;&nbsp;
						<button class="btn" title="删除" name="delete" data-name="<%= i %>"><i class="icon-trash"></i></button>
						<% } %>
                    </td>
                </tr>
                <% } %>
            </tbody>
        </table>
    </script>
<style>
</style>

</head>
<body>
    <header>
        <h1>服务器组</h1>
        <div id="toolbar">
        	<div class="box_1">
        		<button class="btn" id="add"><i class="icon-plus-sign"></i> 添加服务器组</button>
        	</div>  
        </div> 
    </header>	


    <div id="mainbody">
        <div id="servers">
        </div>
    </div>

  <!-- js part
    ================================================== -->
<script src="../assets/js/library/jquery-1.7.1.js"></script>
<script src="../assets/js/library/bootstrap.min.js"></script>
<script src="../assets/js/library/template.js"></script>
<script src="../assets/js/helper.js?t=20130516173114"></script>	
<script src="../assets/js/doc.js?t=20130516173114"></script>
<script>
$(function(){
    var smartMad = window.smartMad = window.smartMad || {};
	var domain = domainURI();
    var version = urlParams('version');
	
    var _url = "http://" + domain + "/mmsapi" + version;
	
	var $servers = $('#servers');
    
    var serversConf = {
        url: _url + "/get/serverGroup/@all"
    };
	
    var serversCall = function(e, json){
    
        var $th = $(this), data, html;
        
        //$th.html(JSON.stringify(json));return;
        ///////////////////////////////////////////////
        
        data = {
            list: json
        };
        
        /////////////////////////////////////////////
        
        html = template('t_a', data);
        $th.html(html);
		
		/////////////////////////////////////////////
		
        $('[name="modify"]').click(function(){
            var name = $(this).attr('data-name');
            location.href = 'editServers.html?name=' + name + '&version=' + urlParams('version');
        });
        
        $('[name="delete"]').click(function(){
            var name = $(this).attr('data-name');
            var conf = {
				type:'get',
                url: _url + "/delete/serverGroup/@self/" + name,
                success: function(json, textStatus, jqXHR){
                    $.tips('已经删除!');
                    this.parent().parent().remove();
                }
            };
            if (confirm('确定删除！')) {
                $(this).delData(conf);
            }
        });
		
        
    };
	
    ///////////////////////////////////////////////////////////////	
    
    $servers.bind('ajax.success', serversCall).getData(serversConf);
	
		
  
	///////////////////////////////////////////////////////////
    
    $('#add').click(function(){
       location.href = 'editServers.html?version=' + version;
    });
    

    
});
</script>
</body>
</html>